package com.zhbcm.treebuilder.web;

import com.zhbcm.treebuilder.bean.SqComment;
import com.zhbcm.treebuilder.common.Result;
import com.zhbcm.treebuilder.common.ResultUtil;
import com.zhbcm.treebuilder.service.ISqCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 朝花不迟暮
 * @since 2021-02-08
 */
@RestController
@RequestMapping("comment")
@Api(tags = "文章评论接口")
public class SqCommentController
{
    @Autowired
    private ISqCommentService commentService;

    @PostMapping("/")
    @ApiOperation("添加或修改评论")
    public Result saveComment(@RequestBody SqComment comment)
    {
        try
        {
            commentService.saveOrUpdate(comment);
            return ResultUtil.success(comment);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return ResultUtil.error();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除评论")
    public Result deleteCommentById(@PathVariable Long id)
    {
        try
        {
            commentService.removeById(id);
            return ResultUtil.success();
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return ResultUtil.error();
    }
}
